package com.download.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.download.web.entity.BusArticle;
import com.download.web.entity.BusArticleLable;
import com.download.web.entity.model.HotTagsModel;
import com.download.web.entity.model.Page;
import com.download.web.mapper.BusArticleLableMapper;
import com.download.web.service.IBusArticleLableService;
import com.download.web.service.IBusArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cmy
 * @since 2019-02-20
 */
@Service
public class BusArcitalLableServiceImpl extends ServiceImpl<BusArticleLableMapper, BusArticleLable> implements IBusArticleLableService {

    @Resource
    private BusArticleLableMapper articleLableMapper;

    @Autowired
    private IBusArticleService articleService;

    @Override
    public List<String> articalLables(Integer artId) {
        return articleLableMapper.selectLables(artId);
    }

    @Override
    public Page<HotTagsModel> hotTagsModelPage(Integer pageIndex, Integer pageSize) {
        List<HotTagsModel> hotTagsModels=articleLableMapper.hotTagsList(pageIndex,pageSize);
        hotTagsModels.forEach(t->{
            BusArticle article=articleService.articleByLatestTag(t.getTagName());
            t.setArtTitle(article.getTitle());
            t.setCreateTime(article.getCreateTime());
            t.setArtId(article.getId());
        });
        return new Page<>(hotTagsModels,articleLableMapper.hotTagsListCount(),pageIndex,pageSize);
    }
}
